package com.ciwong.epaper.modules.reciteWords.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.reciteWords.bean.JiaoCaiDetailBean;


/**
 * Created by keepon on 2018/8/7.
 */
public class BookItemView extends LinearLayout {

	public RelativeLayout mRlContainer;
	private TextView  mTvLearning,mTvBookVersion,mTvGradeName,mTvWordCount,mTvLearnCount;

	public BookItemView(Context context) {
		this(context,null);
	}

	public BookItemView(Context context, AttributeSet attrs) {
		this(context, attrs,0);
	}

	public BookItemView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		LayoutInflater.from(this.getContext()).inflate(R.layout.item_view_book, this);
		init();
	}

	private void init() {
		mRlContainer = findViewById(R.id.iv_icon);
		mTvLearning = findViewById(R.id.tv_learning);
		mTvBookVersion = findViewById(R.id.tv_book_version);
		mTvGradeName = findViewById(R.id.tv_grade_name);
		mTvWordCount = findViewById(R.id.tv_word_count);
		mTvLearnCount = findViewById(R.id.tv_learn_count);

	}

	public void bindData(JiaoCaiDetailBean jiaoCaiDetailBean) {
		if(jiaoCaiDetailBean==null){
			return;
		}
		mTvBookVersion.setText(jiaoCaiDetailBean.getVersionFullName());
		String gradeName = jiaoCaiDetailBean.getGradeName();
		if(jiaoCaiDetailBean.getGradeName().endsWith("学期")){
			gradeName= gradeName.substring(0, gradeName.indexOf("学期"));
		}
		if(jiaoCaiDetailBean.getStatus()>0&&jiaoCaiDetailBean.getLearnCount()>0){
			mTvLearnCount.setVisibility(VISIBLE);
			mTvLearnCount.setText("已学"+jiaoCaiDetailBean.getLearnCount()+"遍");
		}else{
			mTvLearnCount.setVisibility(GONE);
		}
		mTvGradeName.setText(gradeName);
		mTvWordCount.setText(jiaoCaiDetailBean.getWordsCount()+"个单词");
		if(jiaoCaiDetailBean.isSelected()){
			mTvLearning.setVisibility(VISIBLE);
		}else{
			mTvLearning.setVisibility(INVISIBLE);
		}
	}
}
